Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration: refactor network configuration, migrate to chainId, remove unnecessary connectivity polling #1485

Closed
wants to merge 10 commits into from

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Jul 10, 2020

Recommended to review commit by commit—each commit is meant to be a separate PR, but due to changes stacking from one commit to each other, and the possible conflicts that may arise from one PR to another, I've decided to keep all the changes in a single PR.

At the moment, this PR has not been thoroughly tested! Since so many of the changes are built on top of each other, my plan is to do a thorough round of testing after a few more sets of changes (coming soon).

Changes:

  • a4f33cd, 5468dba: Refactors the network configuration
    • Updates some of its fields to be more descriptive
    • Updates some of the copy related to network naming to be aligned on The Ethereum network, The xDai network, The Ethereum Rinkeby test network, etc.
    • Updates some internal function naming
  • 5d24e1f, 47e9d2a: Account module simplifications
  • 584456c: Rename main to ethereum
    • "Mainnet" is not precise as a network selector
  • c456ea8: Updates Network Preferences to be based on chain ID
  • 4f20948: Replace network.type with network.chainId (fixes Remove network.type #1472)
  • d507385: Refactor available networks for onboarding
  • 851e9b6, 9c19599: Remove unused connectivity polling

Note: we are not able to completely eliminate network.type yet, as there are some APIs from aragonUI that need to be updated (see https://github.com/aragon/aragon-ui/pull/788).

@@ -189,7 +184,7 @@ function AccountModule() {
providerInfo={providerInfo}
walletConnectionStatus={walletConnectionStatus}
walletListening={walletListening}
walletOnline={walletListening}
walletOnline={walletOnline}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but I think this should be a fix 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! Haha I can definitely tell you this is a fix. 😆

@@ -71,8 +41,7 @@ export function useWalletConnectionDetails(
isWalletAndClientSynced

const defaultOkConnectionDetails = {
connectionMessage: `Connected to ${walletNetworkName}`,
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't using this key as far as I could tell

Copy link

@andy-hook andy-hook Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the previous implementation wasn't being applied correctly but I do think there does need to be a distinction between a long and short message.

Previously
image

This change
image

The previous version with the button length being shorter than the pop over is a tighter presentation choice imo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this; we definitely want shorter messages for the short connection message.

@@ -32,17 +37,20 @@ export const networkConfigs = {
portisDappId ? { id: 'portis', conf: portisDappId } : null,
].filter(p => p),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the above renamings were more clear:

  • endpoints communicates that this is a network-specific URL much better than nodes.defaultEth
  • environment communicates that this is what will be available in the environment.js file much better than settings does (it's not really network settings anymore)

@@ -105,14 +104,14 @@
"bundlewatch": "bundlewatch",
"start": "node scripts/start",
"start:local": "node scripts/launch-local",
"start:mainnet": "cross-env ARAGON_ETH_NETWORK_TYPE=main npm start",
"start:mainnet": "cross-env ARAGON_ETH_NETWORK_TYPE=ethereum npm start",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started renaming our internal references to "main" or "mainnet" to "Ethereum", as "mainnet" is not descriptive enough (e.g. xDai has a mainnet, Aragon Chain will have a mainnet).

@@ -45,18 +45,6 @@ const INITIAL_DAO_STATE = {
repos: [],
}

const SELECTOR_NETWORKS = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This felt like an odd place to configure the available networks during onboarding, so I've moved it out into the /onboarding folder as static configuration.

componentDidMount() {
// Only the default, because the app can work without the wallet
pollConnectivity([web3Providers.default], connected => {
this.setState({ connected })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I could tell, this connected state is actually not used anymore now that we do the block polling in the Account module.

Good riddance—this was spiking our API requests to ETH nodes!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

? `select the ${sanitizeNetworkType(network.type)} network`
: 'unlock your account'
} in ${getProviderString(
{`Please unlock your account in ${getProviderString(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the Account module, I've simplified places where we check the connect account's network vs. the expected network as the user currently can never have their account enabled on a different network.

@@ -29,28 +27,15 @@ function ValidateWalletWeb3({
)
}

if (isTransaction && walletNetworkType !== networkType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, this state is now impossible to be in

})
const getStoredList = (daoAddress, account) =>
new StoredList(
`activity:chainId-${network.chainId}:${daoAddress}:${account}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this key change will reset any saved activities a user may have held.

In particular, I found it better to use an address here rather than the domain—the same organization can hold multiple (or no) ENS domains.

@@ -7,7 +7,7 @@ import { addressesEqual } from '../web3-utils'

const FavoriteDaosContext = React.createContext()

const storedList = new StoredList(`favorite-daos:${network.type}`)
const storedList = new StoredList(`favorite-daos:chainId-${network.chainId}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, this will reset any saved favourited DAOs.

@@ -17,7 +17,6 @@ import { RoutingProvider } from './routing'
import { ConsoleVisibleProvider } from './apps/Console/useConsole'
import initializeSentryIfEnabled from './sentry'
import { HelpScoutProvider } from './components/HelpScoutBeacon/useHelpScout'
import { ClientBlockNumberProvider } from './components/AccountModule/useClientBlockNumber'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I could tell, there were no uses of this provider's value, as we only show the wallet's sync block (and each connectivity check directly calculates the block drift between the wallet and the read provider).

@@ -100,12 +100,17 @@ export function getLocalChainId() {
return getLocalSetting(LOCAL_CHAIN_ID) || 1337
Copy link
Contributor Author

@sohkai sohkai Jul 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken the liberty of renaming some of the exposed methods to be more clear, without changing the underlying environment variables.

At a future point in time (e.g. as we evaluate snowpack / etc), we can make breaking changes :).

export function getNetworkConfig(id) {
const networkConfig = networkConfigurations[id]
if (!networkConfig) {
throw new Error(`Unsupported network '${id}'`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I've opted to entirely remove the unsupported network configuration.

It's impossible to statically know what chain id to expect in that case, and it's likely better the app just blows up entirely than pretend things are OK.

@@ -266,7 +266,6 @@ export const WalletType = PropTypes.shape({
enable: PropTypes.bool.isRequired,
connected: PropTypes.bool.isRequired,
isContract: PropTypes.bool.isRequired,
networkType: PropTypes.string.isRequired,
providerInfo: PropTypes.object.isRequired,
web3: PropTypes.object.isRequired,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type doesn't seem to be used anywhere, but is perhaps still useful for the sake of documentation?

Anyhow, I've updated it with our wallet.js changes.

@@ -120,12 +119,7 @@ export default {
const adjustedDuration = new BN(duration).toString()
const votingSettings = [adjustedSupport, adjustedQuorum, adjustedDuration]

// Rinkeby has its gas limit capped at 7M, so some larger 6.5M+ transactions are
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things have changed a lot since Sept. 2019; Rinkeby now has a 10M gas limit.

@@ -1,12 +1,61 @@
import tokens from '@aragon/templates-tokens'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this import and just inlined the contents so we can control them better.

Particularly, the import used the network's name rather than chain ID (and to be honest, that package is not particularly helpful).

@@ -145,13 +146,18 @@ const gasPriceApi = 'https://ethgasstation.info/json/ethgasAPI.json'
export async function getGasPrice({
mainnet: { safeMinimum = '3', disableEstimate } = {},
} = {}) {
if (network.type !== 'main') {
// Hardcode 10 for non-mainnet networks
if (network.chainId === CHAIN_IDS.XDAI) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does not appear to be a public API providing gas price estimates on xDai yet... which is probably fine given there are almost no transactions.

@sohkai sohkai marked this pull request as ready for review July 11, 2020 10:31
@sohkai sohkai changed the title Configuration: refactor network configuration, migrate to chainId Configuration: refactor network configuration, migrate to chainId, remove unnecessary connectivity polling Jul 11, 2020
@sohkai sohkai requested review from Evalir and andy-hook July 11, 2020 10:34
Copy link

@andy-hook andy-hook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really solid PR! lots of good changes in here 🚀 🔥 . I've left some comments on areas which stuck out, the main one being how we are accessing endpoints and making sure it's working as expected.

const ts = tokens[network]
const depositer = new web3.eth.Contract(tokens.depositerABI, ts.depositer)
export default (web3, financeAddr, from) => {
if (!testTokensEnabled) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!testTokensEnabled) {
if (!testTokensEnabled()) {

Think we need to call this.

@@ -124,37 +120,40 @@ Network.propTypes = {

const useNetwork = wrapper => {
const [networkError, setNetworkError] = useState(null)
const [ethNode, setEthNodeValue] = useState(defaultEthNode)
const [ethEndpoint, setEthEndpointValue] = useState(network.endpoints.read)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is correct, looks like network is an alias for networkConfig.environment which doesn't contain the endpoints.

Comment on lines 23 to 24
endpoints: {
read: providedDefaultEthNode || 'wss://mainnet.eth.aragon.network/ws',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much prefer this naming! ✨ wonder if eth is more suitable than read?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK read's used as we separate our "read" provider for fetching info, from our write provider (the wallet provider). I actually think this is more clear than eth. 😃

Comment on lines +11 to +19
const PROTECTED_CHAIN_IDS = new Proxy(CHAIN_IDS, {
get(target, property) {
if (property in target) {
return target[property]
} else {
throw new Error(`Chain ID '${property}' not supported`)
}
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rinkeby: new Map(

// Ethereum Rinkeby
[CHAIN_IDS.ETHEREUM]: new Map(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[CHAIN_IDS.ETHEREUM]: new Map(
[CHAIN_IDS.RINKEBY]: new Map(

])
const UNKNOWN_NETWORK_BLOCK_TIME = 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious – Is this still necessary considering the previous change to unsupported network ?

componentDidMount() {
// Only the default, because the app can work without the wallet
pollConnectivity([web3Providers.default], connected => {
this.setState({ connected })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@@ -71,8 +41,7 @@ export function useWalletConnectionDetails(
isWalletAndClientSynced

const defaultOkConnectionDetails = {
connectionMessage: `Connected to ${walletNetworkName}`,
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`,
Copy link

@andy-hook andy-hook Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the previous implementation wasn't being applied correctly but I do think there does need to be a distinction between a long and short message.

Previously
image

This change
image

The previous version with the button length being shorter than the pop over is a tighter presentation choice imo.

Copy link
Contributor

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boom! Quite the changes but all of these things are super clear now. :) Left some comments:

chainId: 1,
name: 'Mainnet',
name: 'Ethereum',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig this new naming a lot; but maybe it can be clearer that this is the Ethereum mainnet network?

@@ -189,7 +184,7 @@ function AccountModule() {
providerInfo={providerInfo}
walletConnectionStatus={walletConnectionStatus}
walletListening={walletListening}
walletOnline={walletListening}
walletOnline={walletOnline}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! Haha I can definitely tell you this is a fix. 😆

@@ -71,8 +41,7 @@ export function useWalletConnectionDetails(
isWalletAndClientSynced

const defaultOkConnectionDetails = {
connectionMessage: `Connected to ${walletNetworkName}`,
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this; we definitely want shorter messages for the short connection message.

Comment on lines +11 to +19
const PROTECTED_CHAIN_IDS = new Proxy(CHAIN_IDS, {
get(target, property) {
if (property in target) {
return target[property]
} else {
throw new Error(`Chain ID '${property}' not supported`)
}
},
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -360,12 +352,10 @@ class SignerPanel extends React.PureComponent {
>
<Screen>
<ValidateWalletWeb3
hasWallet={Boolean(walletWeb3)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely don't remember exactly from where the account and other use-wallet related props are being drilled from, but we could definitely pass the connected prop corresponding to the wallet from use-wallet.

}

export function testTokensEnabled() {
return !!AIRDROP_TOKENS[network.chainId]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make this nicer by applying Boolean(). :)

@stale stale bot added the abandoned label Aug 14, 2020
@aragon aragon deleted a comment from stale bot Aug 14, 2020
@stale stale bot removed the abandoned label Aug 14, 2020
@stale stale bot added the abandoned label Sep 13, 2020
@aragon aragon deleted a comment from stale bot Sep 13, 2020
@stale stale bot removed the abandoned label Sep 13, 2020
@stale stale bot added the abandoned label Oct 15, 2020
@aragon aragon deleted a comment from stale bot Oct 15, 2020
@stale stale bot closed this Oct 23, 2020
@sohkai sohkai reopened this Oct 23, 2020
@stale stale bot removed the abandoned label Oct 23, 2020
@stale stale bot added the abandoned label Nov 22, 2020
@aragon aragon deleted a comment from stale bot Nov 23, 2020
@stale stale bot removed the abandoned label Nov 23, 2020
@stale
Copy link

stale bot commented Dec 24, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for contributing to Aragon! 🦅

@stale stale bot added the abandoned label Dec 24, 2020
@stale stale bot closed this Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove network.type
3 participants